/* $Header: pi_valve.c,v 2.2 01/10/02 10:28:00 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:                                                        */
/* ============                                                        */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* MODULE PURPOSE:                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <p_status.h>
#include <ramps.h>
#include <p_config.h>
#include <zone_config.h>
#include <config.h>
#include <p_filter.h>
#include <zone_status.h>
#include <status.h>
#include <error.h>
#include <iomap.h>
#include <i_op.h>
#include <clock_ui.h>
#include <valve.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

/**begin_proto**/

ON_OFF  GetValveState ( U_INT8 valve_num )

/**end_proto**/
{

    switch ( valve_num )
    {
          case 1:  return (ON_OFF) (( Valve_Power_Image & VALVE1_ON  ) != 0);
          case 2:  return (ON_OFF) (( Valve_Power_Image & VALVE2_ON  ) != 0);
          case 3:  return (ON_OFF) (( Valve_Power_Image & VALVE3_ON  ) != 0);
          case 4:  return (ON_OFF) (( Valve_Power_Image & VALVE4_ON  ) != 0);
          case 5:  return (ON_OFF) (( Zones3_Image      & VLV24_1_ON ) != 0);
          case 6:  return (ON_OFF) (( Zones3_Image      & VLV24_2_ON ) != 0);
          case 7:  return (ON_OFF) (( Zones3_Image      & RELAY1_ON  ) != 0);
          case 8:  return (ON_OFF) (( Zones3_Image      & RELAY2_ON  ) != 0);
          default: return OFF; /* really an error */
    }
}

/**begin_proto**/

UI_ERR  SetValveState (ON_OFF state, U_INT8 valve_num )

/**end_proto**/
{

    if ((state != ON) && (state != OFF)) return INVALID_PARAM;

    if ((valve_num < 1) || (valve_num > 8)) return INVALID_PARAM;

    INTERRUPTS_OFF
/*-------changed by wangwei--------------------*/
printf("call SetValveState\n");
/*
    Active_Wkfile.valve[valve_num-1] = state;

    switch ( valve_num )
    {
          case 1:  if ( state == ON )   Valve_Power_Image |= VALVE1_ON;
                   else                 Valve_Power_Image &= VALVE1_OFF;
                   break;

          case 2:  if ( state == ON )   Valve_Power_Image |= VALVE2_ON;
                   else                 Valve_Power_Image &= VALVE2_OFF;
                   break;

          case 3:  if ( state == ON )   Valve_Power_Image |= VALVE3_ON;
                   else                 Valve_Power_Image &= VALVE3_OFF;
                   break;

          case 4:  if ( state == ON )   Valve_Power_Image |= VALVE4_ON;
                   else                 Valve_Power_Image &= VALVE4_OFF;
                   break;

          case 5:  if ( state == ON )   Zones3_Image |= VLV24_1_ON;
                   else                 Zones3_Image &= VLV24_1_OFF;
                   ZONES_OUT3         = Zones3_Image;
                   break;

          case 6:  if ( state == ON )   Zones3_Image |= VLV24_2_ON;
                   else                 Zones3_Image &= VLV24_2_OFF;
                   ZONES_OUT3         = Zones3_Image;
                   break;

          case 7:  if ( state == ON )   Zones3_Image |= RELAY1_ON;
                   else                 Zones3_Image &= RELAY1_OFF;
                   ZONES_OUT3         = Zones3_Image;
                   break;

          case 8:  if ( state == ON )   Zones3_Image |= RELAY2_ON;
                   else                 Zones3_Image &= RELAY2_OFF;
                   ZONES_OUT3         = Zones3_Image;
                   break;

    }
*/
/*--------------------end change-----------------*/
    INTERRUPTS_ON
    return OK;
}


/**begin_proto**/
void  RTTSetValve1State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF

    if ( (ON_OFF)state == ON )   Valve_Power_Image |= VALVE1_ON;
    else                         Valve_Power_Image &= VALVE1_OFF;


    INTERRUPTS_ON
}

/**begin_proto**/
void  RTTSetValve2State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF

    if ( (ON_OFF)state == ON )   Valve_Power_Image |= VALVE2_ON;
    else                         Valve_Power_Image &= VALVE2_OFF;


    INTERRUPTS_ON
}

/**begin_proto**/
void  RTTSetValve4State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF

    if ( (ON_OFF)state == ON )   Valve_Power_Image |= VALVE4_ON;
    else                         Valve_Power_Image &= VALVE4_OFF;


    INTERRUPTS_ON
}

/**begin_proto**/
void RTTSetValve5State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF
/*------changed by wangwei------------*/
printf("call RTTSetValve5State\n");
/*
    if ( (ON_OFF)state == ON )   Zones3_Image |= VLV24_1_ON;
    else                         Zones3_Image &= VLV24_1_OFF;

    ZONES_OUT3 = Zones3_Image;
*/
/*----------end change--------------*/
    INTERRUPTS_ON
}

/**begin_proto**/
void RTTSetValve6State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF
/*------changed by wangwei------------*/
printf("call RTTSetValve6State\n");
/*
    if ( (ON_OFF)state == ON )   Zones3_Image |= VLV24_2_ON;
    else                         Zones3_Image &= VLV24_2_OFF;

    ZONES_OUT3 = Zones3_Image;
*/
/*----------end change--------------*/

    INTERRUPTS_ON
}

/**begin_proto**/
void RTTSetRelay1State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF
/*------changed by wangwei------------*/
printf("call RTTSetRelay1State\n");
/*
    if ( (ON_OFF)state == ON )   Zones3_Image |= RELAY1_ON;
    else                         Zones3_Image &= RELAY1_OFF;

    ZONES_OUT3 = Zones3_Image;
*/
/*----------end change--------------*/

    INTERRUPTS_ON
}

/**begin_proto**/
void RTTSetRelay2State ( INT32 state )
/**end_proto**/
{
    INTERRUPTS_OFF
/*------changed by wangwei------------*/
printf("call RTTSetRelay2State\n");
/*
    if ( (ON_OFF)state == ON )   Zones3_Image |= RELAY2_ON;
    else                         Zones3_Image &= RELAY2_OFF;

    ZONES_OUT3 = Zones3_Image;*/
/*----------end change--------------*/

    INTERRUPTS_ON
}

/**begin_proto**/
void CTSetValve1State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 1 );
/*-------changed by wangwei--------------*/
printf("call CTSetValve1State\n");
//      CTValveAnnotate (1, state);
/*----------end change------------------*/
}

/**begin_proto**/
void CTSetValve2State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 2 );
/*-------changed by wangwei--------------*/
printf("call CTSetValve2State\n");
//      CTValveAnnotate (2, state);
/*----------end change-------------------*/
}

/**begin_proto**/
void CTSetValve3State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 3 );

/*-------changed by wangwei--------------*/
printf("call CTSetValve3State\n");
//      CTValveAnnotate (3, state);
/*----------end change-------------------*/

}

/**begin_proto**/
void CTSetValve4State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 4 );

/*-------changed by wangwei--------------*/
printf("call CTSetValve4State\n");
//      CTValveAnnotate (4, state);
/*----------end change-------------------*/
}

/**begin_proto**/
void CTSetValve5State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 5 );

/*-------changed by wangwei--------------*/
printf("call CTSetValve5State\n");
//      CTValveAnnotate (5, state);
/*----------end change-------------------*/
}

/**begin_proto**/
void CTSetValve6State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 6 );

/*-------changed by wangwei--------------*/
printf("call CTSetValve6State\n");
//      CTValveAnnotate (6, state);
/*----------end change-------------------*/
}

/**begin_proto**/
void CTSetRelay1State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 7 );

/*-------changed by wangwei--------------*/
printf("call CTSetValve7State\n");
//      CTValveAnnotate (7, state);
/*----------end change-------------------*/
}

/**begin_proto**/
void CTSetRelay2State ( INT32 state )
/**end_proto**/
{
      (void)SetValveState(  (ON_OFF)state, 8 );

/*-------changed by wangwei--------------*/
printf("call CTSetValve8State\n");
//      CTValveAnnotate (8, state);
/*----------end change-------------------*/
}

/**begin_proto**/
void ResetValveState ( void )
/**end_proto**/
{

/*-------changed by wangwei--------------*/
printf("call ResetValveState\n");
/*
    RTTSetValve1State( Active_Wkfile.valve[0]);
    RTTSetValve2State( Active_Wkfile.valve[1]);
    RTTSetValve3State( Active_Wkfile.valve[2]);
    RTTSetValve4State( Active_Wkfile.valve[3]);
    RTTSetValve5State( Active_Wkfile.valve[4]);
    RTTSetValve6State( Active_Wkfile.valve[5]);
    RTTSetRelay1State( Active_Wkfile.valve[6]);
    RTTSetRelay2State( Active_Wkfile.valve[7]);
    RestoreMultiposValve();
*/
/*---------end change------------------*/
}

